﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMS_MAV.DTO.Carrier;
using WMS_MAV.DTO.FinanceType;
using WMS_MAV.DTO.Receivable;

namespace WMS_MAV.Controllers
{
    public class ReceivableController : Controller
    {
        private readonly IConfiguration _configuration;
        public ReceivableController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 应收视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ReceivableShow()
        {
            return View();
        }
        /// <summary>
        /// 返回应收状态
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetReceivableStatusShow(string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Receivable/GetReceivableStatus";
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 返回应收数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetReceivableShow(ReceivableShowDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Receivable/GetReceivableList?PageIndex=" + dto.PageIndex + "&pageSize=" + dto.PageSize + "&receivableSerialNumber=" + dto.ReceivableSerialNumber + "&receivableName=" + dto.ReceivableName + "&financeTypeName=" + dto.FinanceTypeName + "&payer=" + dto.Payer + "&startTime=" + dto.StartTime + "&endTime=" + dto.EndTime + "&status=" + dto.Status;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetReceivableAdd(ReceivableAddDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetReceivableAdd";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 删除应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetReceivableDel(FinanceTypeDelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetReceivableDelete";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 批量删除应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetReceivableDelRange(ReceivableRangeDelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetReceivableDeleteRange";
            var list = "{\"ids\":" + dto.Ids + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 查看应收详情
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetReceivableModel(ReceivableModelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Receivable/GetReceivableModel?receivableId=" + dto.ReceivableId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetReceivableUpd(ReceivableUpdDto obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetReceivableUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 审批应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetReceivableAudit(ReceivableAuditDto obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetReceivableAudit";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 添加实收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetAuditAdd(AuditAddDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Receivable/GetActualpaymentAdd";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
    }
}
